<template>
  <div class="body">
    <Head school="imgdata" title="发布" xs="1" fh="1" icon="" bgcolor="1" />
    <div class="content">
      <div class="cont_top">
        <div class="box">
          <ul>
            <li v-for="(value, index) in dataL" :key="index">
              <div>
                <div>
                  <img :src="value" alt="" />
                  <div>
                    <input type="text" placeholder="添加备注" />
                  </div>
                </div>
                <div class="el-icon-close" @click="deleteimg(index)"></div>
              </div>
            </li>
          </ul>
        </div>
      </div>
      <div class="cont_bom">
        <div class="cont_ms">
          <div>
            <input
              class="ad"
              type="text"
              name=""
              id=""
              placeholder="请添加标题"
            />
          </div>
          <div>
            <span class="el-icon-location-outline"></span
            ><input class="ad" type="text" placeholder="位置" />
          </div>
          <div>
            <span class="el-icon-collection-tag"></span
            ><input class="ad" type="text" placeholder="标签" />
          </div>
          <div>
            <span class="el-icon-notebook-2"></span>
            <div>
              <select name="" id="">
                <option value="日常">日常</option>
                <option value="好玩">好玩</option>
                <option value="快乐">快乐</option>
                <option value="伤心">伤心</option>
                <option value="疯狂">疯狂</option>
                <option value="聚会">聚会</option>
                <option value="风景">风景</option>
                <option value="奇物">奇物</option>
              </select>
            </div>
          </div>
        </div>
        <div class="btn" @click="fbtz">
          <span>马上发布</span>
        </div>
      </div>
    </div>
  </div>
</template>
<script>
import Head from "../../components/Fb_body/Head.vue";
export default {
  name: "Fb",
  components: {
    Head,
  },
  data() {
    return {
      dataA: this.$route.params.data,
      //这里接收Fb_body Head.vue 发送过来的数据 this.$route.params.名字
      //注意区分 $router 和 $route 的区别
      dataL: [],
      num: 0,
    };
  },
  methods: {
    deleteimg(index) {
      this.dataL.splice(index, 1);
    },
    fbtz() {
      let ad = document.getElementsByClassName("ad");
      let zt = 0;
      for (let a = 0; a < ad.length; a++) {
        if (ad[a].value == "") {
          zt = 1;
        }
      }
      if (zt == 1) {
        alert("不能为空");
      } else {
        alert("发布成功");
        this.$router.push("/");
        return;
      }
    },
  },
  mounted() {
    let flag = true;
    if (this.dataA == undefined) {
      alert("您还未选择图片");
      this.$router.push({ name: "Fabu" });
      return;
    }
    let time = setInterval(() => {
      // console.log(this.dataA);
      if (this.num < this.dataA.length) {
        if (flag) {
          flag = false;
          this.ajax({
            method: "post",
            url: "/queryAllimg",
            data: {
              id: this.dataA[this.num],
            },
          }).then((res) => {
            // console.log(res.data[0].imgurl);
            this.dataL.push(res.data[0].imgurl);
            this.num++;
            flag = true;
          });
        }
      } else {
        console.log("gunbi", this.dataL);
        clearInterval(time);
      }
    });
  },
};
</script>
<style lang="scss" scoped>
.body {
  background-color: #f3f3f3;
  height: 896px;
}
.content {
  padding: 5px;
  margin-top: 5px;
  > .cont_top {
    overflow-y: scroll;
    > .box {
      height: 580px;
      // background-color: brown;
      > ul {
        list-style: none;
        > li {
          margin-bottom: 10px;
          > div {
            position: relative;
            box-shadow: 0px 0px 5px gray;
            > div:nth-of-type(1) {
              width: 100%;
              > img {
                width: 100%;
                height: 234px;
              }
              > div {
                width: 100%;
                height: 35px;
                background-color: white;
                > input {
                  width: 350px;
                  height: 35px;
                  border: none;
                  outline: none;
                  margin-left: 15px;
                  font-size: 17px;
                }
              }
            }
            > div:nth-of-type(2) {
              background-color: #5d79b3;
              color: white;
              border-radius: 3px;
              width: 22px;
              height: 22px;
              text-align: center;
              line-height: 24px;
              font-size: 20px;
              position: absolute;
              top: 0;
              right: 0;
              cursor: pointer;
            }
          }
        }
      }
    }
  }
  > .cont_bom {
    margin-top: 10px;
    box-shadow: 0px 0px 1px gray;
    > .cont_ms {
      > div:nth-of-type(1) {
        > input {
          width: 95%;
          height: 37px;
          outline: none;
          border: none;
          font-size: 19px;
          margin-left: 10px;
          font-weight: bold;
        }
      }
      > div:nth-of-type(2) {
        width: 100%;
        height: 45px;
        display: flex;
        justify-content: space-around;
        align-items: center;
        > input {
          width: 330px;
          height: 40px;
          outline: none;
          border: none;
          font-size: 19px;
          margin-left: 1px;
        }
        > span {
          font-size: 25px;
          cursor: pointer;
        }
      }
      > div:nth-of-type(3) {
        width: 100%;
        height: 45px;
        display: flex;
        justify-content: space-around;
        align-items: center;
        > input {
          width: 330px;
          height: 40px;
          outline: none;
          border: none;
          font-size: 19px;
          margin-left: 1px;
        }
        > span {
          font-size: 25px;
          cursor: pointer;
        }
      }
      > div:nth-of-type(4) {
        width: 100%;
        height: 45px;
        display: flex;
        justify-content: space-around;
        align-items: center;
        > span {
          font-size: 25px;
        }
        > div {
          width: 330px;
          height: 40px;
          > select {
            width: 330px;
            height: 40px;
            background-color: white;
            border: none;
            font-size: 19px;
            cursor: pointer;
          }
        }
      }
      > div {
        border-bottom: 1px solid rgba(128, 128, 128, 0.432);
        background-color: white;
      }
    }
    > .btn {
      width: 100%;
      height: 41px;
      background-color: #5d79b3;
      text-align: center;
      cursor: pointer;
      margin-top: 5px;
      > span {
        line-height: 41px;
        color: white;
        font-size: 22px;
        font-weight: bold;
      }
    }
  }
}
</style>